package com.tau.egonetwork.excel;

import com.tau.egonetwork.facebook.FacebookFriendProfile;
import com.tau.egonetwork.facebook.FacebookMainProfile;
import com.tau.egonetwork.facebook.FacebookUtils;
import com.tau.egonetwork.profiles.Group;
import com.tau.egonetwork.profiles.MainProfile;
import com.tau.egonetwork.profiles.Profile;

class FacebookExcel implements IExcel {

	@Override
	public MainProfile<?> createMainProfile(String name) {
		return new FacebookMainProfile(FacebookUtils.generateRandomID(), name);
	}

	@Override
	public Profile<?> createProfile(String name) {
		return new FacebookFriendProfile(FacebookUtils.generateRandomID(), name);
	}

	@Override
	public void addToFriendsList(MainProfile<?> main, Profile<?> friend) {
		FacebookMainProfile profile = (FacebookMainProfile)main;
		FacebookFriendProfile friendProfile = (FacebookFriendProfile)friend;
		profile.getFriendsList().add(friendProfile);
	}

	@Override
	public void createConnection(Profile<?> p1, Profile<?> p2) {

		//cast specifically:
		FacebookFriendProfile f1 = (FacebookFriendProfile)p1;
		FacebookFriendProfile f2 = (FacebookFriendProfile)p2;
		
		//create if not exists:
		if (f1.getFriendsList() == null)
			f1.createFriendsList();
		if (f2.getFriendsList() == null)
			f2.createFriendsList();
		
		//create said connection:
		f1.getFriendsList().add(f2);
		f2.getFriendsList().add(f1);
		
	}

	@Override
	public Group<?> createGroup(String name) {
		return new Group<Long>(name);
	}

	@SuppressWarnings("unchecked")
	@Override
	public void addToGroup(Group<?> group, Profile<?> profile) {
		Group<Long> g = (Group<Long>)group;
		FacebookFriendProfile p = (FacebookFriendProfile)profile;
		g.add(p);
	}

	@SuppressWarnings("unchecked")
	@Override
	public void addGroup(Group<?> group, MainProfile<?> mainProfile) {
		FacebookMainProfile p = (FacebookMainProfile)mainProfile;
		Group<Long> g = (Group<Long>)group;
		p.getGroupsList().add(g);
	}
	
}
